package logic

import (
	"context"
	"goods-guru/models/mysql"

	"goods-guru/goodrpc/goodrpc"
	"goods-guru/goodrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodListLogic) GoodList(in *goodrpc.GoodListRequest) (*goodrpc.GoodListResponse, error) {
	// todo: add your logic here and delete this line
	var goods []mysql.Good
	mysql.DB.Table("goods").
		Select("good.*,classes.name as class_name,brands.name as brand_name").
		Joins("left join classes on classes.Id = good.class_id").
		Joins("left join brands on brands.Id = good.brand_id").
		Find(&goods)
	for _, good := range goods {
		list := goodrpc.GoodList{
			Title:     good.Title,
			ClassName:
			BrandName: string(good.BrandId),
			GoodId:    int64(good.ID),
		}
		mysql.DB.Debug().Find(&list)
	}
	return &goodrpc.GoodListResponse{
		List: goods.ID,
	}, nil
}
